#include "widget.h"
#include "ui_widget.h"
#include <QDateTime>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //通过两个时间段的差来计算两者相差多少天多少个小时
    QDateTime OldTime = ui->dateTimeEdit_old->dateTime();
    QDateTime NewTime = ui->dateTimeEdit_new->dateTime();
    int day = OldTime.daysTo(NewTime);
    int second = OldTime.secsTo(NewTime);
    //计算多余的天数
    int hours = (second / 3600) % 24;
    QString text = QString("爱你已经持续了") + QString::number(day) + QString("天，")
            + QString::number(hours) + QString("小时");
    //设置到label中
    ui->label->setText(text);
}

Widget::~Widget()
{
    delete ui;
}


